<template>
	<view class="container">
		<view class="goods-section">
			<block v-for="val in orderInfo" :key="val.id">
				<view class="g-item">
					<image :src="val.imgList[0].url"></image>
					<view class="right">
						<text class="title clamp">{{ val.spuName }}</text>
						<view class="price-box">
							<text class="price">{{ val.amount }}积分</text>
						</view>
						<view class="price-box" style='margin-left: -10upx;'>
							<text class="number">x {{ val.total }}</text>
						</view>
					</view>
				</view>
			</block>
		</view>

		<view class="yt-list">
			<view class="cu-form-group">
				<view class="title">用户姓名</view>
				{{ dataInfo.userName }}
			</view>
			<view class="cu-form-group">
				<view class="title">手机号码</view>
				{{ dataInfo.mobile }}
			</view>
			<view class="cu-form-group">
				<view class="title">下单时间</view>
				{{ this.formatDate(dataInfo.updateDate) }}
			</view>
			<view class="cu-form-group">
				<view class="title">收货地址</view>
				<view style="width: 50%;">{{ dataInfo.address }}</view>
			</view>
		</view>

		<view class="yt-list">
			<view class="cu-form-group">
				<view class="title">商品数量</view>
				{{ totals }}份
			</view>
			<view class="cu-form-group">
				<view class="title">使用积分</view>
				{{ numPar }}积分
			</view>
			<view class="cu-form-group">
				<view class="title">订单状态</view>
				<span v-if="dataInfo.deliveryStatus == 'DFH'">待发货</span>
				<span v-if="dataInfo.deliveryStatus == 'DSH'">已发货</span>
				<span v-if="dataInfo.deliveryStatus == 'YWC'">订单完成</span>
			</view>
			<view class="cu-form-group" v-if="dataInfo.deliveryStatus == 'DSH'">
				<view class="title">物流单号</view>
				<view id="copy">{{dataInfo.wlh}}</view>
			</view>

		</view>

		<!-- <view class="page-bottom" v-if="dataInfo.deliveryStatus == 'DSH'">
			<view class="action-btn-group">
				<button type="primary" class="action-btn no-border buy-now-btn" @click="wlhAction()">复制物流单号</button>

				<button type="primary" v-if="orderInfo[0].status == 'NO'" class="action-btn no-border buy-now-btn" @click="toggleSpec()">查看福利码</button>
				<button type="primary" v-if="orderInfo[0].status == 'YES'" class=" action-btn no-border buy-now-btn">线下已兑换</button>
				<button type="primary" class=" action-btn no-border add-cart-btn">加入购物车</button>
			</view>
		</view> -->
		<!-- 规格-模态层弹窗 -->
		<view
			class="popup spec"
			:class="specClass"
			@touchmove.stop.prevent="stopPrevent"
			@click="toggleSpec"
		>
			<!-- 遮罩层 -->
			<view class="mask"></view>
			<view class="layer attr-content" @click.stop="stopPrevent">
				<view class="out-style">
					<view class="shop-outside">
						<view class="shop-info">
							<!-- <span>{{qrCodeInfo.goodsName}}</span> -->
							<!-- <span>￥</span>
							<span>123</span>
							<span>214</span> -->
						</view>
						<view class="code-div">
							<view class="qrcode-item">
								<canvas canvas-id="qrcode" style="margin: auto;width: 230px;height: 230px;border-radius: 5px;" />
							</view>
						</view>
						<view class="text-style">
							<span>请出示二维码进行核销</span>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import calendar from '@/components/heqifang-calendar/calendar.vue';
import uniNumberBox from '@/components/uni-number-box.vue';
import uQRCode from '@/js_sdk/Sansnn-uQRCode/uqrcode.js'
import { getOpenidMsg, productInfo, insertUserIntegralReciveRecord, selectUserIntegralById, selectUserIntegralReciveRecordById } from 'api/shop';
export default {
	components: {
		calendar,
		uniNumberBox
	},
	data() {
		return {
			modalName: null,
			buyInfo: [],
			formItem: {},
			shopList: [],
			shopId: '',
			totalNum: '0',
			userInfo: {
				mobile: '',
				name: ''
			},
			surplus:'0',
			totals: '',
			num:1,
			orderInfo:{},
			qrCodeInfo:{},
			dataList:[],
			specClass: 'none',
			specInfoClass:'none',
			numPar:'',
			dataInfo:{}
		};
	},
	onLoad(options) {
		this.getOpenidMsgAction()
		//接收传值,id里面放的是标题，因为测试数据并没写id
		let id = options.id;
		if(id){
			this.init(id)
			this.productId = id
			// this.$api.msg(`点击了${id}`);
		}
	},
	methods: {
		wlhAction(){
			console.log('复制')
			let text = document.getElementById("text").innerText;
			let input = document.getElementById("input");
			input.value = text; // 修改文本框的内容
			input.select(); // 选中文本
			document.execCommand("copy"); // 执行浏览器复制命令
		},
		getOpenidMsgAction() {
			getOpenidMsg().then(ret => {
				if (ret.data.errcode === 0) {
					let data = ret.data.data.result;
					if (data) {
						if (data.cardNo === null || data.cardNo === '' || data.cardNo === undefined) {
							this.handle();
						} else {
							this.userInfo = data;
						}
					} else {
						this.handle();
					}
				} else if (ret.data.errcode === 9999 || ret.data.errcode === 9991) {
					this.handle();
				} else {
					this.$api.msg(ret.data.errmsg);
					return false;
				}
			})
		},

		handle() {
			// window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
			let ua = window.navigator.userAgent.toLowerCase();
			// 通过正则表达式匹配ua中是否含有MicroMessenger字符串
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        //是微信浏览器
        window.location.href = this.$xeUtils.locat().origin + '/yq/#/handle-submit'
				// window.location.href = 'https://shengst.tripln.top/subsidy/#/city-card-handle';
			} else {
				window.location.href = 'https://shengst.tripln.top/subsidy/#/city-card-handle-app';
			}
		},
		cancel(){
			this.modalName = ''
		},
		//时间戳转换
		formatDate(date) {
			var date = new Date(date);
			var YY = date.getFullYear() + '-';
			var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
			var DD = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
			var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
			var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
			var ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
			return YY + MM + DD +' ' +hh+mm+ss;
		},
		init(id) {
			selectUserIntegralReciveRecordById({batch: id}).then(ret => {
				if (ret.data.errcode === 0) {
					this.orderInfo = ret.data.data
					let num = 0
					let total = 0
					for (const val of this.orderInfo) {
						num +=  val.amount * val.total
						total += val.total
					}

					this.numPar = num
					this.totals = total

					this.dataInfo = ret.data.data[0]
					// this.orderInfo.imgurl = ret.data.data.imgList[0].url
				} else {
					this.$api.msg(ret.data.errmsg);
					return false
				}
			})
		},
		toggleSpec(data) {
			if(this.specClass === 'show'){
				this.specClass = 'hide';
				setTimeout(() => {
					this.specClass = 'none';
				}, 250);
			}else if(this.specClass === 'none'){
				this.specClass = 'show';
				this.qrcode(this.orderInfo)
			}
		},
		stopPrevent() {},
		qrcode(data){
			console.log(data,'999')
			uQRCode.make({
				canvasId: 'qrcode',
				componentInstance: this,
				text: 'jfjf:'+data[0].id,
				size: 230,
				margin: 20,
				backgroundColor: '#ffffff',
				foregroundColor: '#000000',
				fileType: 'jpg',
				correctLevel: uQRCode.defaults.correctLevel,
				success: res => {
				  // console.log(res)
				}
			  })
		},
	}
};
</script>

<style lang="scss">
	.page-bottom .action-btn-group:after{
		border-right: 0 !important;
	}
	.text-style{
		text-align: center;
	}
	.container{
		padding: 0 10px 10px 10px;
	}
	page {
		background: $page-color-base;
		padding-bottom: 100upx;
	}

	.address-section {
		padding: 30upx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90upx;
			color: #888;
			font-size: 44upx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28upx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34upx;
			margin-right: 24upx;
		}

		.address {
			margin-top: 16upx;
			margin-right: 20upx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32upx;
			color: $font-color-light;
			margin-right: 30upx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5upx;
		}
	}

	.goods-section {
		margin-top: 16upx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84upx;
			padding: 0 30upx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50upx;
			height: 50upx;
			border-radius: 100px;
		}

		.name {
			font-size: 30upx;
			color: $font-color-base;
			margin-left: 24upx;
		}

		.g-item {
			display: flex;
			margin: 20upx 30upx;
			padding-top: 20upx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140upx;
				height: 140upx;
				border-radius: 4upx;
			}

			.right {
				flex: 1;
				padding-left: 24upx;
				overflow: hidden;
			}

			.title {
				font-size: 30upx;
				color: $font-color-dark;
			}

			.spec {
				font-size: 26upx;
				color: $font-color-light;
			}

			.price-box {
				display: flex;
				align-items: center;
				font-size: 30upx;
				color: $font-color-dark;
				padding-top: 10upx;

				.price {
					margin-bottom: 4upx;
					color: #fa436a;
				}
				.number {
					font-size: 26upx;
					color: $font-color-base;
					margin-left: 20upx;
				}
			}

			.step-box {
				position: relative;
			}
		}
	}
	.yt-list {
		margin-top: 16upx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10upx 30upx 10upx 40upx;
		line-height: 70upx;
		position: relative;
		.title{
			color: #f85e52;
		}

		.hb {
			color: #ffaa0e;
		}

		.lpk {
			color: #3ab54a;
		}


		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		.cell-icon {
			height: 32upx;
			width: 64upx;
			font-size: 22upx;
			color: #fff;
			text-align: center;
			line-height: 32upx;
			background: #f85e52;
			border-radius: 4upx;
			margin-right: 12upx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}
		}

		.cell-more {
			align-self: center;
			font-size: 24upx;
			color: $font-color-light;
			margin-left: 8upx;
			margin-right: -10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26upx;
			color: $font-color-light;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 26upx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}
			&.red {
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90upx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}

	/* 支付列表 */
	.pay-list {
		padding-left: 40upx;
		margin-top: 16upx;
		background: #fff;
		.pay-item {
			display: flex;
			align-items: center;
			padding-right: 20upx;
			line-height: 1;
			height: 110upx;
			position: relative;
		}
		.icon-weixinzhifu {
			width: 80upx;
			font-size: 40upx;
			color: #6bcc03;
		}
		.icon-alipay {
			width: 80upx;
			font-size: 40upx;
			color: #06b4fd;
		}
		.icon-xuanzhong2 {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 40upx;
			color: $base-color;
		}
		.tit {
			font-size: 32upx;
			color: $font-color-dark;
			flex: 1;
		}
	}

	.footer {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90upx;
		justify-content: space-between;
		font-size: 30upx;
		background-color: #fff;
		z-index: 99;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
		.price-content {
			padding-left: 30upx;
		}
		.price-tip {
			color: $base-color;
			margin-left: 8upx;
		}
		.price {
			font-size: 36upx;
			color: $base-color;
		}
		.submit {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 280upx;
			height: 100%;
			color: #fff;
			font-size: 32upx;
			background-color: $base-color;
		}
	}

	/* 优惠券面板 */
	.mask {
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0, 0, 0, 0);
		z-index: 9995;
		transition: 0.3s;

		.mask-content {
			width: 100%;
			min-height: 30vh;
			max-height: 70vh;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: 0.3s;
			overflow-y: scroll;
		}
		&.none {
			display: none;
		}
		&.show {
			background: rgba(0, 0, 0, 0.4);

			.mask-content {
				transform: translateY(0);
			}
		}
	}

	/* 优惠券列表 */
	.coupon-item {
		display: flex;
		flex-direction: column;
		margin: 20upx 24upx;
		background: #fff;
		.con {
			display: flex;
			align-items: center;
			position: relative;
			height: 120upx;
			padding: 0 30upx;
			&:after {
				position: absolute;
				left: 0;
				bottom: 0;
				content: '';
				width: 100%;
				height: 0;
				border-bottom: 1px dashed #f3f3f3;
				transform: scaleY(50%);
			}
		}
		.left {
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			overflow: hidden;
			height: 100upx;
		}
		.title {
			font-size: 32upx;
			color: $font-color-dark;
			margin-bottom: 10upx;
		}
		.time {
			font-size: 24upx;
			color: $font-color-light;
		}
		.right {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 26upx;
			color: $font-color-base;
			height: 100upx;
		}
		.price {
			font-size: 44upx;
			color: $base-color;
			&:before {
				content: '￥';
				font-size: 34upx;
			}
		}
		.tips {
			font-size: 24upx;
			color: $font-color-light;
			line-height: 60upx;
			padding-left: 30upx;
		}
		.circle {
			position: absolute;
			left: -6upx;
			bottom: -10upx;
			z-index: 10;
			width: 20upx;
			height: 20upx;
			background: #f3f3f3;
			border-radius: 100px;
			&.r {
				left: auto;
				right: -6upx;
			}
		}
	}
	.appointment-date-item::after {
		font-family: cuIcon;
		display: block;
		content: '\e6a3';
		position: absolute;
		font-size: 17px;
		color: #8799a3;
		line-height: 50px;
		width: 30px;
		text-align: center;
		top: 0;
		bottom: 0;
		right: -10px;
		margin: auto;
	}

	/*  弹出层 */
	.popup {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 99;

		&.show {
			display: block;
			.mask {
				animation: showPopup 0.2s linear both;
			}
			.layer {
				animation: showLayer 0.2s linear both;
			}
		}
		&.hide {
			.mask {
				animation: hidePopup 0.2s linear both;
			}
			.layer {
				animation: hideLayer 0.2s linear both;
			}
		}
		&.none {
			display: none;
		}
		.mask {
			position: fixed;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: 1;
			background-color: rgba(0, 0, 0, 0.4);
		}
		.layer {
			position: fixed;
			z-index: 99;
			bottom: 0;
			width: 100%;
			min-height: 40vh;
			border-radius: 10upx 10upx 0 0;
			background-color: #fff;
			.btn {
				height: 66upx;
				line-height: 66upx;
				border-radius: 100upx;
				background: $uni-color-primary;
				font-size: $font-base + 2upx;
				color: #fff;
				margin: 30upx auto 20upx;
			}
		}
		@keyframes showPopup {
			0% {
				opacity: 0;
			}
			100% {
				opacity: 1;
			}
		}
		@keyframes hidePopup {
			0% {
				opacity: 1;
			}
			100% {
				opacity: 0;
			}
		}
		@keyframes showLayer {
			0% {
				transform: translateY(120%);
			}
			100% {
				transform: translateY(0%);
			}
		}
		@keyframes hideLayer {
			0% {
				transform: translateY(0);
			}
			100% {
				transform: translateY(120%);
			}
		}

	}
	.uni-numbox{
		position: inherit;
	}
	.text-green, .line-green, .lines-green{
		color: #fa436a;
	}
	.bg-green{
		background-color: #fa436a;
	}
	/* 底部操作菜单 */
		.page-bottom{
			padding: 0 20upx;
			position:fixed;
			left: 0;
			bottom:0;
			z-index: 95;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 100upx;
			background: rgba(255,255,255,.9);
			box-shadow: 0 0 20upx 0 rgba(0,0,0,.5);
			// border-radius: 16upx;

			.p-b-btn{
				display:flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				font-size: $font-sm;
				color: $font-color-base;
				width: 96upx;
				height: 80upx;
				.yticon{
					font-size: 40upx;
					line-height: 48upx;
					color: $font-color-light;
				}
				&.active, &.active .yticon{
					color: $uni-color-primary;
				}
				.icon-fenxiang2{
					font-size: 42upx;
					transform: translateY(-2upx);
				}
				.icon-shoucang{
					font-size: 46upx;
				}
			}
			.action-btn-group{
				width: 100%;
				display: flex;
				height: 76upx;
				border-radius: 100px;
				overflow: hidden;
				box-shadow: 0 20upx 40upx -16upx #fa436a;
				box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
				background: linear-gradient(to right, #ffac30,#fa436a,#F56C6C);
				/* margin-left: 20upx; */
				position:relative;
				&:after{
					content: '';
					position:absolute;
					top: 50%;
					right: 50%;
					transform: translateY(-50%);
					height: 28upx;
					width: 0;
					border-right: 1px solid rgba(255,255,255,.5);
				}
				.action-btn{
					display:flex;
					align-items: center;
					justify-content: center;
					width: 180upx;
					height: 100%;
					font-size: $font-base ;
					padding: 0;
					border-radius: 0;
					background: transparent;
				}
			}
		}


</style>
